from libs.pyqt5braisedpork.window.dialog import BaseDialog
from libs.pyqt5braisedpork.window.generic import NoBorderWindow

from .controller import LoginController, RegisterController

from ui.login.login import Ui_login_form
from ui.login.register import Ui_register_form


class LoginWindow(NoBorderWindow, LoginController, Ui_login_form):
    """登录窗口"""
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.qss = r"static/qss/login.qss"
        self.qss_render()   # 加载 QSS

        self.signal_binder()
        self.addition_ui()

    def signal_binder(self):
        """在此绑定信号"""
        self.pushButton_close.clicked.connect(self.close_action)  # 关闭信号
        self.pushButton_min.clicked.connect(self.min_action)      # 最小化信号
        self.pushButton_register.clicked.connect(lambda: self.show_register_window(RegisterDialogWindow))  # 注册框展示

    def addition_ui(self):
        # 设置控件阴影
        effect_shadow = self.get_shadow((198, 201, 255), 6, offset=(2, 3))
        effect_shadow2 = self.get_shadow((102, 204, 255), 7, offset=(1, 1))

        self.pushButton_login.setGraphicsEffect(effect_shadow2)
        self.label_user.setGraphicsEffect(effect_shadow)


class RegisterDialogWindow(BaseDialog, RegisterController, Ui_register_form):
    """注册对话窗类"""
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.signal_binder()

    def signal_binder(self):
        """在此绑定信号"""
        self.pushButton_register.clicked.connect(self.register)  # 注册
